package model

import (
	"math"
	"time"
)

const (
	DATETIME_FORMAT = "2006-01-02 15:04:05"
	DATE_FORMAT     = "2006-01-02"
	MONTH_FORMAT    = "2006-01"
)

type ObjectMeta struct {
	ID        int       `gorm:"primary_key;AUTO_INCREMENT;column:id"`
	CreatedAt time.Time `gorm:"column:created_at"`
	UpdatedAt time.Time `gorm:"column:updated_at"`
}

type ListOptions struct {
	Page   int `json:"page"`
	Size   int `json:"size"`
	Offset int `json:"offset"`
}

func NewListOPtions(page, size int) ListOptions {
	l := ListOptions{
		Page: page,
		Size: size,
	}
	if page > 0 || size > 0 {
		_ = l.GetOffset()
	}
	return l
}

func (l *ListOptions) GetOffset() int {
	if l.Offset > 0 {
		return l.Offset
	}
	l.Offset = l.Size * (l.Page - 1)
	return l.Offset
}

type ListMeta struct {
	Total     int
	Pagecount int
}

func NewListMeta(total, size int) ListMeta {
	lm := ListMeta{Total: total}
	if size > 0 {
		lm.Pagecount = int(math.Ceil(float64(total) / float64(size)))
	}
	return lm
}
